package com.example.chapter0410;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ListView listView = findViewById(R.id.listview);
        ArrayList<HashMap<String,Object>> list = new ArrayList<>();
        String[] sname = getResources().getStringArray(R.array.sname);
        int[] sid = getResources().getIntArray(R.array.sid);
        for (int i = 0; i <sid.length ; i++) {
            HashMap<String,Object> map = new HashMap<>();
            map.put("img",R.drawable.ic_launcher_background);
            map.put("sname",sname[i]);
            map.put("sid",sid[i]);
            list.add(map);
        }
        SimpleAdapter simpleAdapter = new SimpleAdapter(
                this,
                list,
                R.layout.list_item,new String[]{"img","sname","sid"},
                new int[]{R.id.imageView,R.id.sname,R.id.sid});
        listView.setAdapter(simpleAdapter);
    }
}